package homework12月8号.homework1.h7;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;

/*"1.现有Person类，包含属性String id，String name ，int age
2.data1.txt中存放了Person类的全限定名（包名+类名）,data2.txt中存放了 Person类的属性信息内容如下
id=p001
name=小虎
age=20
3.定义测试类，在测试类中通过解析data1.txt，使用反射来获取Person实例。通过解析data2.txt来给Person赋值。"
*/
public class Demo1 {
    public static void main(String[] args) throws IOException, Exception {
        List<String> list = FileUtils.readLines(new File("D:\\ldea dashuju\\day.12.6\\src\\czxy\\homework\\h7\\data1.txt"));
        //获取
        for (String s : list) {
            Class<?> aClass = Class.forName(s);
            Object person = aClass.newInstance();
            List<String> list1 = FileUtils.readLines(new File("D:\\ldea dashuju\\day.12.6\\src\\czxy\\homework\\h7\\data2.txt"));
            for (String s1 : list1) {
                String s2 = s1.split("=")[0];
                Field f = aClass.getDeclaredField(s2);
                f.setAccessible(true);
                String s3 = s1.split("=")[1];
                f.set(person, s3);
                System.out.println(f.get(person));
            }
        }
    }
}
